<?php

namespace app\api\controller;

use think\Db;

use app\common\controller\Logined;
use app\common\service\TranslateService;
class Sys extends Logined{

	/*
	轮播图
	*/
	public function getSlideshow() {
		$data = Db::table('tp_slideshow')->where('status', 1)->select();
		if($data){
			$this->retData(0,'success',$data);
		} else {
			$this->retData(0,'fail');
		}
	}

	/*
	新手问答
	*/

	public function question(){
		$data = Db::table('tp_question')->select();
		if($data){
			$this->retData(0,'success',$data);
		} else {
			$this->retData(0,'fail');
		}
	}

	/*
	微信 社群
	*/
	public function weiTeam(){
		$data = C('weixin_team_code');
		if($data){
			$this->retData(0,'success',$data);
		} else {
			$this->retData(0,'fail');
		}
	}

	/*
	客服账户
	 */
	public function kfAccount(){
		$uid = $this->uid;
		if(empty($uid)){
			$this->retData(1,'缺少参数用户ID(uid)');
		}
		$data = [];
		$aaa = Db::table('tp_user_team')->where('x_uid',$uid)->column('uid');
// 		$admin = Db::table('tp_admin')->order('data_uid desc')->column('data_uid');
// 		$pid = $this->user_info['pid'];
// 		$data_uid = 0;
		$data_uid = Db::table('tp_admin')->where('data_uid','in',$aaa)->order('data_uid desc')->value('data_uid');
// 		while ($pid) {
// 			if (in_array($pid, $admin)) {
// 				$data_uid = $pid;
// 				break;
// 			} else {
// 				$pid = Db::table('tp_user')->where('id',$pid)->value('pid');
// 			}
// 		}
		if ($data_uid) {
			$data['kf1'] = Db::table('tp_admin')->where('data_uid',$data_uid)->value('kf1');
			$data['kf2'] = Db::table('tp_admin')->where('data_uid',$data_uid)->value('kf2');
			$data['kf3'] = Db::table('tp_admin')->where('data_uid',$data_uid)->value('kf3');

			if (!$data['kf1']) {
				$data['kf1'] = C('kf_code1');
			}
			if (!$data['kf2']) {
				$data['kf2'] = C('kf_code2');
			}
			if (!$data['kf3']) {
				$data['kf3'] = C('kf_code3');
			}
		} else {
			$data['kf1'] = C('kf_code1');
			$data['kf2'] = C('kf_code2');
			$data['kf3'] = C('kf_code3');
		}
		
		// $data['kf2'] = explode(',', $data['kf2']);
		$this->retData(0,'success',$data);
	}


	public function isOpen(){
		$type = (int)P('type')?:1;
		switch ($type) {
			case 1:
				$param = 'exchange_status';
				break;
			case 2:
				$param = 'withdrawal_status';
				break;
			case 3:
				$param = 'transfer_status';
				break;
			case 4:
				$param = 'out_status';
				break;
			default:
				# code...
				break;
		}
		$data = C($param);
		$this->retData(0,'success',$data);
	} 



    //官网地址
    public function gw(){
    	$data = C('gw_url');
		if($data){
			$this->retData(0,'success',$data);
		} else {
			$this->retData(0,'fail');
		}
    }

    public function block(){
    	$data = C('block_url');
		if($data){
			$this->retData(0,'success',$data);
		} else {
			$this->retData(0,'fail');
		}
    }
}